﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Http;
using System.Collections.Specialized;
using System.Web;
using App.Composers;
using App.Domain.Model;

namespace App.Service.WebAPI.Controllers
{
    public abstract class ControllerBase : ApiController
    {
        protected NameValueCollection QueryString { get { return HttpUtility.ParseQueryString(Request.RequestUri.Query); } }
        protected string RequestUriWithExtension
        {
            get
            {
                if (string.IsNullOrWhiteSpace(Request.RequestUri.Query))
                    return Request.RequestUri.AbsoluteUri;
                else
                    return Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.Query, string.Empty);
            }
        }
        protected string UriExtension
        {
            get
            {
                string[] parts = RequestUriWithExtension.Split('.');
                if (parts.Length > 1)
                    return parts[1];
                else
                    return null;
            }
        }
        protected string RequestUri
        {
            get
            {
                if (string.IsNullOrWhiteSpace(UriExtension))
                    return RequestUriWithExtension;
                else
                    return RequestUriWithExtension.Replace("." + UriExtension, string.Empty);
            }
        }

        protected Logic bal = DomainComposer.Instance.BusinessLogic;
    }
}
